package com.hronline;

import com.delegate.ManagerDashBoardDelegate;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

public class ManagerDashboardStackActivity extends FragmentActivity implements ManagerDashBoardDelegate{
	
	ManagerDashboardActivity dashboardFragment;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.fragmentstackctivity);
		showDashboardPage();
	}
	
	void addFragment(Fragment fragment, boolean addToBackStack, int transition) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        ft.replace(R.id.simple_fragment, fragment);
        ft.setTransition(transition);
        if (addToBackStack)
            ft.addToBackStack(null);
        ft.commit();
    }

//    public void launchNewActivity(View v) {
//        Intent intent = new Intent(v.getContext(), ExampleActivity.class);
//        startActivity(intent);
//    }

    public void finishFragmentOrActivity(View v) {
        FragmentManager manager = getSupportFragmentManager();
        if (manager.getBackStackEntryCount() > 0)
            getSupportFragmentManager().popBackStack();
        else
            finish();
    }

    public void launchNewFragment(Fragment fragment) {
        launchNewFragment(dashboardFragment);
    }
    
    /* ========================================================================== */
    /* ===============================SELECTOR=================================== */
    /* ========================================================================== */
    private void showDashboardPage(){
    	if(dashboardFragment == null){
    		dashboardFragment	=	new ManagerDashboardActivity(this, this);
    	}
    	
    	addFragment(dashboardFragment, true, FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
    }
    
    
    /* ========================================================================== */
    /* ===============================DELEGATE=================================== */
    /* ========================================================================== */

	@Override
	/* this method is used to open the login page */
	public void openLoginPage() {
		// TODO Auto-generated method stub
		/* reset all user data caching */
		Constant.resetAllUserDataCaching(this, MODE_PRIVATE);
		
		Intent intent	=	new Intent(this, LoginActivity.class);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		this.startActivity(intent);
		
		/* destroy the current activity */
		finish();
	}
    
}
